//ExtraTurn

#include "PUExtraTurn.h"
#include "Game.h"
#include "input.h"
#include "Controller.h"
#include "Player.h"
#include "ENUM.h"

PUExtraTurn::PUExtraTurn()
{
	state = MOVE_PLAYER;
	PU_name = "Extra Turn Power-Up";
}
PUExtraTurn::~PUExtraTurn(){}

int PUExtraTurn::Execute(Input* input, Player* player, Text* text)
{
	switch(state)
	{
	case PLACE_TILE:
		{
			//set instructions
			text->setText("PLACE YOUR SECOND TILE!\n"
							 "Hold <CTRL> for help.");
			if(input->KeyDown(DIK_LCONTROL) || input->KeyDown(DIK_RCONTROL))
			{
				text->setText(	"* Use <SHIFT> keys to look at your current goal.\n"
								"* Use <TAB> key to look at artifacts on tiles\n"
								"* Use W, A, S, D while holding the <TAB> key to move to a different selected tile\n"
								"* Use A, D, Left arrow, or Right arrow keys to move extra tile.\n"
								"* Use W, S, Up arrow, or Down arrow keys to rotate extra tile.\n"
								"* Use <SPACE> to shift tile into board.\n");
			}

			Controller::Instance()->getBoard()->setCurrentTile(player->getCurrentTile());
			//Tile movement
			if(input->KeyPressed(DIK_A) || input->KeyPressed(DIK_LEFT))
				Controller::Instance()->getBoard()->shiftExtraPosDown();
			if(input->KeyPressed(DIK_D) || input->KeyPressed(DIK_RIGHT))
				Controller::Instance()->getBoard()->shiftExtraPosUp();
			if(input->KeyPressed(DIK_W) || input->KeyPressed(DIK_UP))
				Controller::Instance()->getBoard()->RotateExtraTileClock();
			if(input->KeyPressed(DIK_S) || input->KeyPressed(DIK_DOWN))
				Controller::Instance()->getBoard()->RotateExtraTileCounterClock();
			if(input->KeyPressed(DIK_SPACE))
			{
				Tile* tile = Controller::Instance()->getBoard()->boardShift();
				player->Collect();
				
				for(int i=0;i<NUM_PLAYERS;++i)
				{
					if(player[i].getCurrentTile() == Controller::Instance()->getBoard()->getExtraTile())
						player[i].SetBoardPosition(tile);//***
				}
				state = MOVE_PLAYER;
				return MOVE;
			}
			return STAY;
		}
	case MOVE_PLAYER:
		{
			//Set font for the move player case
			text->setText("MOVE PLAYER.\n"
						  "Hold <CTRL> for help.");

			if(input->KeyDown(DIK_LCONTROL) || input->KeyDown(DIK_RCONTROL))
			{
				text->setText(	"* Use <SHIFT> keys to look at your current goal.\n"
								"* Use <TAB> key to look at artifacts on tiles\n"
								"* Use W, A, S, D while holding the <TAB> key to move to a different selected tile\n"
								"* Use WASD to move player.\n"
								"* Use <SPACE> to set player position and end turn.\n");
			}

			Controller::Instance()->getBoard()->setCurrentTile(player->getCurrentTile());
			//player movement
			if(input->KeyPressed(DIK_W) || input->KeyPressed(DIK_UP))
				player->MoveNorth();
			if(input->KeyPressed(DIK_A) || input->KeyPressed(DIK_LEFT))
				player->MoveWest();
			if(input->KeyPressed(DIK_S) || input->KeyPressed(DIK_DOWN))
				player->MoveSouth();
			if(input->KeyPressed(DIK_D) || input->KeyPressed(DIK_RIGHT))
				player->MoveEast();
			if(input->KeyPressed(DIK_SPACE))
			{
				player->Collect();
				state = PLACE_TILE;
			}
		}
	}
	return STAY;
}